module.exports = function ($resource, $state, $http, $q, FileUploader, toaster, $modal,$stateParams) {
  
	return {

		restrict: 'AE',
		template: require('../views/pendingreviewlist.html'),
		replace: true,
		scope: {
			'saleobj': '=',
			'funobj': '=',
			'baseinfo': '=',
			'util': '=',
			'reviewflag' : '=',
		},
		link: function (scope, elements, attrs) {
      scope.type = $stateParams.type;
      console.log(scope.type);
      scope.flag = {
        'planning_state' : '0',
        'project_state' : '3'
      }
      var params = {};
      scope.url = '';
      if(scope.type == '0'){ // 区县复核规划处
        scope.url = '/api/as/ggc/reviewPlanning/findInfoList';
        params = {
          'city_project' : '0',
          'planning_state' : '0',
          'project_state' : '3'
        }
      } else if(scope.type == "1"){ // 市级复核
        scope.url = '/api/as/ggc/reviewPlanning/findInfoList';
        params = {
          'city_project' : '1',
          'planning_state' : '0',
          'project_state' : '3'
        }
      } else if(scope.type == "3"){ // 区县复核责任处室
        scope.url = '/api/as/ggc/reviewCityResponsible/approvalList';
        params = {
          'city_project' : '0',
          'project_state' : '1',
          'recommend_city' : '0',
          'recommend_district' : '1'
        }
      } 
			/* 分页
			* ========================================= */
			scope.maxSize = 5;             //最多显示多少个按钮
			scope.bigCurrentPage = 1;      //当前页码
			scope.itemsPerPage = 10         //每页显示几条
			
			scope.getlist = function () {
				var para = {
					pageNo:scope.bigCurrentPage, 
					pageSize:scope.itemsPerPage,
				};
				para = angular.extend(params, para);
				$resource(scope.url, {}, {}).
				save(para,function(res) {
					console.log(para);
					if (res.errcode !== 0) {
						toaster.error({title:"",body:res.errmsg});
						return;
					}
					console.log(res);
					scope.objs = res.data.results;
					scope.bigTotalItems = res.data.totalRecord;
				})
			};

      scope.$watch('reviewflag', function(){
        scope.getlist();
      }, true)
      // 查验复核
			scope.toinfo = function(info){
				var modalInstance = $modal.open({
					template: require('../views/projectinfounfh.html'),
					controller: 'projectinfounfhs',
					size: 'lg',
					resolve: {
						iteminfo: function () {
							return info;
            },
            'type': function () {
							return scope.type;
						}
						
					}
				});
				modalInstance.result.then(function (showResult) {
					scope.reviewflag++;	
					// scope.getlist();
				});
			}

			// 推荐原因
      scope.rejectInfo= function (info) {
				console.log('尽力了')
				var modalInstance = $modal.open({
					template: require('../views/reason.html'),
					controller: 'reasons',
					size: 'lg',
					resolve: {
						iteminfo: function () {
							return info;
            },
            'type': function () {
							return scope.type;
						},
						'flag': function () {
							return '10'
						}
					}
				});
				modalInstance.result.then(function (showResult) {
          scope.examineflag++;
				});
			}
    }
	}
}